unit BD_PgmCalMT_Aux;

interface
uses System.Classes, System.SysUtils, Vcl.Forms;

type TLogData = (
                  WorkOrderNumber,
                  SerialNumber,
                  PassFailStatus,
                  FlashOnOff,
                  RetestStatus,
                  Bat1Meas,
                  Bat2Meas,
                  PresMeasZeroPres,
                  PresA2DAvgCalcZeroPres,
                  PresA2DMaxCalcZeroPres,
                  PresA2DMinCalcZeroPres,
                  PresA2DDiffCalcZeroPres,
                  Stage1A2DAvgCalcZeroPres,
                  Stage1A2DMaxCalcZeroPres,
                  Stage1A2DMinCalcZeroPres,
                  Stage1A2DDiffCalcZeroPres,
                  PresLeak1Meas,
                  PresLeak2Meas,
                  PresLeakCalc,
                  PresMeasFullPres,
                  PresA2DAvgCalcFullPres,
                  PresA2DMaxCalcFullPres,
                  PresA2DMinCalcFullPres,
                  PresA2DDiffCalcFullPres,
                  Stage1A2DAvgCalcFullPres,
                  Stage1A2DMaxCalcFullPres,
                  Stage1A2DMinCalcFullPres,
                  Stage1A2DDiffCalcFullPres,
                  PresMeasReturnZero,
                  PresA2DAvgCalcReturnZero,
                  PresA2DMaxCalcReturnZero,
                  PresA2DMinCalcReturnZero,
                  PresA2DDiffCalcReturnZero,
                  Stage1A2DAvgCalcReturnZero,
                  Stage1A2DMaxCalcReturnZero,
                  Stage1A2DMinCalcReturnZero,
                  Stage1A2DDiffCalcReturnZero,
                  Bat3Meas,
                  A1Calc,
                  C1Calc,
                  HysteresisCalc,
                  VersionUUT,
                  WRPresA2DMaxCnfg,
                  WRPresA2DMinCnfg,
                  WRBgnInflCnfg,
                  WRDsplMaxAtmBarCnfg,
                  WRDsplMaxPSICnfg,
                  WRDsplMinCnfg,
                  WREndInflCnfg,
                  WRGelCnfg,
                  WRMaxAllowedInflsCnfg,
                  WRStage1A2DMaxAllowedCnfg,
                  WRStage1A2DMinAllowedCnfg,
                  WROcclusionPresCnfg,
                  WROcclusionTimeCnfg,
                  WRAllowUnitsCnfg,
                  WRLedDimFreqCnfg,
                  WRLedDimPresResetCnfg,
                  WRLedOffPresResetCnfg,
                  WRLedNormalFreqCnfg,
                  WROffTimeCnfg,
                  WROnUnitsCnfg,
                  WRPrsrValCnfg,
                  WRRZWindowCnfg,
                  WRStabilizingPresCnfg,
                  WRLedDimActivationTimeCnfg,
                  WRLedOffActivationTimeCnfg,
                  WRAutoOffActivationTimeCnfg,
                  WRTotStage1A2DSamplesCnfg,
                  WRTotPresSamplesCnfg,
                  WRZWindowCnfg,
                  WRPresBlinkDutyCycleCnfg,
                  WRTotalPresA2DReadsPerPresCnfg
                );

procedure InitParamGrid;
procedure UpdateParamGrid;


implementation
uses BDPgmCalMTMain;
(*******************************************************************************
  InitParamGrid: Initializes the fixed rows and colums of the UUT Parameters grid.
********************************************************************************)
procedure InitParamGrid;
var
  FixedRowInfo: TStringList; i, MaxWidth: Integer;
begin
  FixedRowInfo := TStringList.Create;
  try
    //Load in the 32 parameter names that are programmed in the UUT during calibration
    if FileExists(ExtractFilePath(Application.ExeName)+'BD_Parameter_List.txt',False) then
      begin
        FixedRowInfo.LoadFromFile(ExtractFilePath(Application.ExeName)+'BD_Parameter_List.txt' );
        frmMain.Memo1.Lines.Add('Loading UUT Parameter labels.');
      end
      else
        begin
          frmMain.Memo1.Lines.Add('Unable to find file '+ ExtractFilePath(Application.ExeName)+'BD_Parameter_List.txt');
          Exit;
        end;
    //initialize the parameter grid label column with the parameter names
    frmMain.sgUUTParameters.RowCount := FixedRowInfo.Count - 1;
    //Display the parameters in the label column of the grid, and find the widest string of all params
    MaxWidth := 0;   //initialize
    for i := 0 to FixedRowInfo.Count-1 do
      begin
        frmMain.sgUUTParameters.Cells[0,i] := FixedRowInfo[i];
        if frmMain.sgUUTParameters.Canvas.TextWidth(frmMain.sgUUTParameters.Cells[0,i]) > MaxWidth then
          MaxWidth := frmMain.sgUUTParameters.Canvas.TextWidth(frmMain.sgUUTParameters.Cells[0,i]);
      end;
    //Now set the column 0 (parameter lables) width the match the widest parameter string
    frmMain.sgUUTParameters.ColWidths[0] := MaxWidth + 28;
    frmMain.sgUUTParameters.ColWidths[1] := frmMain.sgUUTParameters.Width - frmMain.sgUUTParameters.ColWidths[0] - 4;
    frmMain.sgUUTParameters.Height := (frmMain.sgUUTParameters.RowCount * frmMain.sgUUTParameters.RowHeights[0]) +
                                      (frmMain.sgUUTParameters.RowCount * 1);
  finally
    FixedRowInfo.Clear;
  end;
end;

(*******************************************************************************
  UpdateParamGrid: Writes the paramater values that will be sent to the UUT
                   to the Parameter Grid.
********************************************************************************)
procedure UpdateParamGrid;
var
  i, j: integer; pB: pByte;
begin
  i := 1;
  j := 0;
  while i <= 29 do
  begin
    pB := @UUT.bParams[i+1];
    frmMain.sgUUTParameters.Cells[1,j] := UUT.ExtractWord(pB).ToString;
    inc(i,2);
    inc(j,1);
  end;
  i := 31;     //force i to the start of the single byte params.
  while i < High(UUT.bParams) do
  begin
    frmMain.sgUUTParameters.Cells[1,j] := (UUT.bParams[i]).ToString;
    inc(i);
    inc(j);
  end;
end;


end.
